package com.xingxuecn.demos.controller;

import com.xingxuecn.demos.dao.domain.User;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/*
* 搭建SpringMvc：
* 1.web.xml中配置前端控制器（拦截所有请求用"/"而不要用"/*"）
* 2.web.xml指明SpringMVC的配置XML路径
* 3.SpringMVC的配置XML中扫描Controller包
* 4.构建视图解析器
* 5.新建Controller
*
*
* */

/**
 * 用户控制器
 * @author Kris at 2018/9/27 17:23
 */
@Controller
@RequestMapping("test")
public class TestController {

    /**
     * 返回视图：第一种方式：返回String
     * 万能的Controller方法参数（需要的请求参数，内置对象都可以直接用Controller方法参数接受）
     * @return
     */
    @RequestMapping("index")
    public String index(Model model, String str, HttpServletRequest request, HttpServletResponse response){
        model.addAttribute("str",str);
        return "user";
    }

    /**
     * 返回视图：第二种方式：返回ModelAndView对象
     * @return
     */
    @RequestMapping("mav")
    public ModelAndView mav(){
        ModelAndView mav = new ModelAndView("user");
        mav.getModel().put("str","随便历来");
        return mav;
    }

    @RequestMapping("detail")
    @ResponseBody
    public User detail(){
        User user = new User();
        user.setAccount("zouni");
        user.setNick("走你");
        return user;
    }



}
